/*
* 包含 n 个接口函数的模块
* 函数的返回值: promise对象
* */
import ajax from './ajax'
// const BASE_URL = 'http://localhost:3001'
const BASE_URL = '/api'

// 测试
// export const reqIndex = () => ajax(`${BASE_URL}/index`)
// http://ftp6261168.host107.abeiyun.cn/jd/api/shopcart.json

/*
* 获取首页数组对象
* */
export const reqIndex = () => ajax('/index')

/*
* 获取分类数据
* */
export const reqCategories = () => ajax('/categories')

/*
* 获取商品数据
* */
export const reqGoods = () => ajax(`${BASE_URL}/goods`)

/*
* 获取短信验证码
* phone: 手机号
* */
export const reqSendCode = (phone) => ajax(`${BASE_URL}/sendcode`, {phone})

/*
* 手机号验证码登录
* phone: 手机号
* code: 验证码
* */
export const reqSmsLogin = ({phone, code}) => ajax(`${BASE_URL}/login_sms`, {phone, code}, 'POST')

/*
* 账号密码登录
* username: 账号
* password: 密码
* captcha: 图像验证码
* */
export const reqPwdLogin = ({username, password, captcha}) => ajax(`${BASE_URL}/login_pwd`, {
  username,
  password,
  captcha
}, 'POST')

/**
 *根据会话获取用户信息
 */
export const reqUserInfo = () => ajax(BASE_URL + '/userinfo')

/**
 * 用户登出
 */
export const reqLogout = () => ajax(BASE_URL + '/logout')

/*
* 根据用户id来获取购物车商品
* */
export const reqCartGoods = (ids) => ajax(`${BASE_URL}/cartgoods/${ids}`)
